<template>
	<view class="mainpadding beijingse">
		<!-- 性别选择弹出层 -->
		<u-picker :show="show" :columns="columns" closeOnClickOverlay @close="show=false" @cancel="show=false"
			@confirm="confirmSex"></u-picker>
		<view class="flexbetween mainpadding ffffff radius">
			<view class="ershib">真实姓名</view>
			<input class="inputs textright" type="text" placeholder="请输入真实姓名" v-model="real_name">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">身份证号</view>
			<input class="inputs textright" type="text" placeholder="请输入身份证号" v-model="id_card">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">性别</view>
			<view class="flexleft" style="justify-content: flex-end;" @click="show=true">
				<input class="inputs textright margin_right2" type="text" placeholder="请选择性别" disabled v-if="!sex">
				<view class="inputs textright margin_right2" v-if="sex">{{sex}}</view>
				<view class="right_icon"></view>
			</view>
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">工作单位</view>
			<input class="inputs textright" type="text" placeholder="请输入工作单位" v-model="workdw">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">职业</view>
			<input class="inputs textright" type="text" placeholder="请输入职业" v-model="zy">
		</view>
		<view class="flexbetween margin_top">
			<view class="scsfz" v-if="upImg!=''">
				<image :src="upImg" mode=""></image>
			</view>
			<view class="scsfz" @click="uploadImg" v-if="!upImg">
				<image src="https://logist.kongzhongwangluo.top/uploads/20230527/ad2c33cd4e69ab1ee86ca0c964430f89.png" mode=""></image>
			</view>
			<view class="scsfz" v-if="upImgtext!=''">
				<image :src="upImgtext" mode=""></image>
			</view>
			<view class="scsfz" @click="uploadImgtext" v-if="!upImgtext">
				<image src="https://logist.kongzhongwangluo.top/uploads/20230527/df59e8da3674a2aae92c008620a36525.png" mode=""></image>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click.stop="smrz">
			<view class="bigbtn">提交审核</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				upImg: "",
				upImgtext: "",
				id_card: "",//身份证号
				real_name: "",//姓名
				zy:"",//职业
				show: false, //性别选择弹出层
				sex: "",
				columns: [
					['男', '女', ]
				],
				workdw:"",
			}
		},
		onShow() {

		},
		methods: {
			// 实名认证
			smrz() {
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				if (this.real_name == "") {
					uni.hideLoading()
					httpRequest.toast("请输入真实姓名")
					return
				}
				if (this.id_card == "") {
					uni.hideLoading()
					httpRequest.toast("请输入身份证号")
					return
				}
				let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				if (reg.test(this.id_card) === false) {
					httpRequest.toast("请输入正确的身份证号")
					uni.hideLoading()
					return false;
				}
				if (this.sex == "") {
					uni.hideLoading()
					httpRequest.toast("请选择性别")
					return
				}
				if (this.pro == "") {
					uni.hideLoading()
					httpRequest.toast("请选择职业")
					return
				}
				if (this.upImg == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证头面像")
					return
				}
				if (this.upImgtext == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证国徽面")
					return
				}
				httpRequest.request('/api/user/realnameRz', 'GET', {
					// 传参
					real_name: this.real_name, //真实姓名
					id_card: this.id_card, //身份证号
					id_card_zimage: this.upImg, //身份证正面
					id_card_fimage: this.upImgtext, //身份证反面
					workdw:this.workdw,
					zy:this.zy
				}, false, false, true).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				}).catch(err => {
					uni.hideLoading()
					httpRequest.toast(err.msg);
				})
			},
			uploadImg() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {

						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {

									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.upImg = image_item
				}).catch(err => {});
			},
			uploadImgtext() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {

						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageServicetext(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {

									_this.uploadImageServicetext(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageServicetext(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.upImgtext = image_item

				}).catch(err => {});
			},
			// 跳转审核状态页面
			/* 	tzshz() {
					uni.navigateTo({
						url: '/pages/mypage/shenheshangjrz'
					})
				}, */
			confirmSex(e) { //选择性别
				this.sex = e.value[0]
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scsfz {
		width: 48%;
		height: 291rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.inputs {
		width: 60%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}
</style>